<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>
 	用户名: <input type="text" name="" class="userName">
 	密码: <input type="text" name="" class="passWord">

 	<button>登录</button>

 	<script type="text/javascript">
 		let btn = document.querySelector("button")

 		btn.onclick = function(){
 			// 1.application/x - www-form-urlencoded
 			let xhr = new XMLHttpRequest()

 			xhr.open("post","http://47.104.167.34:9100/prod-api/login")
 			xhr.setRequestHeader("content-type","application/json")
 			let obj = {
 				username: 'admin01',
 				password: '123456'
 			}
 			xhr.send(JSON.stringify(obj))

 			xhr.onreadystatechange = function(){
 				if (xhr.readyState == 4) {
 					let res = JSON.parse(xhr.responseText)
 					console.log(res)
 					if(res.code == 200){
 						localStorage.setItem("Au", res.token)
 						getInfo()
 					}
 				}
 			}
 		}

 		function getInfo(){
 			// getInfo接口
 			// token设置
 			// Auttorization:
 			let xhr = new XMLHttpRequest()

 			xhr.open("get","http://47.104.167.34:9100/prod-api/getInfo")
 			xhr.setRequestHeader("Authorization","Bearer " + localStorage.getItem("Au"))
 			xhr.send()
 			xhr.onreadystatechange = function(){
 				if (xhr.readyState == 4) {
 					let res = JSON.parse(xhr.responseText)
 					console.log(res)
 				}
 			}
 		}
 		getInfo()
 	</script>
</body>
</html>